package com.dzqc.fly.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * 类名称: DateTimeUtil
 * 类描述: 日期工具类
 * 创建人: tonghl
 * 创建时间: 2022年06月29日 上午10:01:05
 * @version v1.0.0
 *
 */
public class DateTimeUtil {

    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYYMMDD_HHMM = "yyyyMMdd HH:mm";
    public static final String YYYYMMDD_HHMMSS = "yyyyMMdd HH:mm:ss";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    /**
     * 判断是否日期格式
     *
     * @param obj
     * @return
     */
    public static Boolean isDateType(Object obj) {
        if (obj.equals(null))
            return false;
        if (("" + obj).length() < 8)
            return false;
        else
            return true;
    }

    /**
     * 获取今天日期
     *
     * @return yyyy-MM-dd
     */
    public static String getToday() {
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }

    public static String getToday(String format) {
        return new SimpleDateFormat(format).format(new Date());
    }

    public static Date convertToDateTime(Object obj) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            if(obj!=null){
                date = sdf.parse(obj.toString());
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }

    public static Integer dateDiff(String howToCompare, Date startDate,
                                   Date endDate) {
        return null;
    }

    public static String replaceDigtalToChineseNumber(String date) {
        return null;
    }

    public static String replaceChineseNumber(String date) {
        return null;
    }

    public static String convertChineseYear(String date) {
        return null;
    }

    public static String convertChineseMonth(String date) {
        return null;
    }

    public static String convertChineseDate(String date) {
        return null;
    }

    public static String convertChineseWeek(Integer day) {
        return null;
    }

    public static Date getMondyDayOfWeek(Date dt) {
        return null;
    }

    public static Date getStartDayOfWeek(Date dt) {
        return null;
    }

    public static Date getDateIndexOfWeek(Date dt) {
        return null;
    }

    public static Integer getHolidayType(Date dt) {
        return null;
    }

    // 添加日期
    public static String addDate(String date, Integer dateCount, String formatType) {
        SimpleDateFormat sdf = new SimpleDateFormat(formatType);
        Date date2;
        Calendar calendar = null;
        try {
            date2 = sdf.parse(date);
            calendar = Calendar.getInstance();
            calendar.setTime(date2);
            calendar.add(calendar.DATE, dateCount);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return sdf.format(calendar.getTime());
    }

    // 判断相隔多少天
    public static Integer haveDays(String startDate, String endDate) {
        long days = -1;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = null;
        Date date2 = null;
        try {
            date1 = sdf.parse(startDate);
            date2 = sdf.parse(endDate);
            long result = date2.getTime() - date1.getTime();
            days = result / (24 * 60 * 60 * 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return NumberUtil.convertToInt(days);
    }

    /**
     * 两个时间相隔多长时间
     * @param fomate       转换格式
     * @param startDate    开始时间
     * @param endDate      结束时间
     * @return
     */
    public static Integer haveMinutes(String fomate, String startDate, String endDate){
        long minutes = -1;
        SimpleDateFormat sdf = new SimpleDateFormat(fomate);
        Date date1 = null;
        Date date2 = null;
        try {
            date1 = sdf.parse(startDate);
            date2 = sdf.parse(endDate);
            long result = date2.getTime() - date1.getTime();
            minutes = result / ( 60 * 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return NumberUtil.convertToInt(minutes);
    }
}

